Micron Document
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| SparkN0de-git | SparkN0de |
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


Displaying Raw • Download


meshchatx/src/backend/async_utils.py 0889cd0a049c6706bf41db77434579dee930d13c (0889cd0a) Text, 883 B

Tff7b72import T7ee787asyncio
Tff7b72from T7ee787collectionsT7ee787.T7ee787abc Tff7b72import Te6edf3Coroutine


Tff7b72class T56d364AsyncUtilsTb4b4b4:
T8b949e# remember main loop
Te6edf3main_loopTb4b4b4: Te6edf3asyncioTff7b72.Td2a8ffAbstractEventLoop Tff7b72| Tff7b72None Tff7b72= Tff7b72None

Tf0883e@staticmethod
Tff7b72def Td2a8ffset_main_loopTb4b4b4(Te6edf3loopTb4b4b4: Te6edf3asyncioTff7b72.Td2a8ffAbstractEventLoopTb4b4b4)Tb4b4b4:
Te6edf3AsyncUtilsTff7b72.Td2a8ffmain_loop Tff7b72= Te6edf3loop

T8b949e# this method allows running the provided async coroutine from within a sync function
T8b949e# it will run the async function on the main event loop if possible, otherwise it logs a warning
Tf0883e@staticmethod
Tff7b72def Td2a8ffrun_asyncTb4b4b4(Te6edf3coroutineTb4b4b4: Te6edf3CoroutineTb4b4b4)Tb4b4b4:
T8b949e# run provided coroutine on main event loop, ensuring thread safety
Tff7b72if Te6edf3AsyncUtilsTff7b72.Td2a8ffmain_loop Tff7b72and Te6edf3AsyncUtilsTff7b72.Td2a8ffmain_loopTff7b72.Td2a8ffis_runningTb4b4b4(Tb4b4b4)Tb4b4b4:
Te6edf3asyncioTff7b72.Td2a8ffrun_coroutine_threadsafeTb4b4b4(Te6edf3coroutineTb4b4b4, Te6edf3AsyncUtilsTff7b72.Td2a8ffmain_loopTb4b4b4)
Tff7b72return

T8b949e# main event loop not running...
Tffa657printTb4b4b4(Ta5d6ff"Ta5d6ffWARNING: Main event loop not available. Could not schedule task.Ta5d6ff"Tb4b4b4)


──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────